package main;

import java.util.*;

public class Interrupt extends TimerTask {
	private int interruptSeconds;
	private boolean interrupted;
	private Thread interruptThread;
	private Object interruptObject;

	public int getInterruptSeconds() {
		return interruptSeconds;
	}

	public boolean isInterrupted() {
		return interrupted;
	}

	public Interrupt(int _interruptSeconds, Thread _interruptThread) {
		interrupted = false;
		interruptSeconds = _interruptSeconds;
		interruptThread = _interruptThread;
	}

	public Interrupt(int _interruptSeconds, Object _interruptobject) {
		interrupted = false;
		interruptSeconds = _interruptSeconds;
		interruptObject = _interruptobject;
	}

	public void run() {
		try {
			interrupted = true;
			if (interruptThread != null) {
				interruptThread.stop();
			}
			if (interruptObject != null) {
				((Interruptible) (interruptObject)).interrupt();
			}
			this.cancel();
		} catch (Exception e) {
			System.out.println(e.toString());
		}
	}

}
